﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using OpcUaHelper.Model;
using Configuration.ServerApi.Dao;
using Configuration.ServerApi.Param;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Configuration.ServerApi.Service.Impl
{
    /// <summary>
    /// DeviceService
    /// </summary>
    public class DeviceService : IDeviceService
    {
        private readonly IConfiguration Configuration;
        private readonly IHttpContextAccessor Accessor;
        private readonly IBisDeviceConfigDao BisDeviceConfigDao;

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="accessor"></param>
        /// <param name="bisDeviceConfigDao"></param>
        public DeviceService(IConfiguration configuration,
            IHttpContextAccessor accessor,
            IBisDeviceConfigDao bisDeviceConfigDao)
        {
            Configuration = configuration;
            Accessor = accessor;
            BisDeviceConfigDao = bisDeviceConfigDao;
        }

        #endregion 构造函数

        #region 获取所有节点数据

        /// <summary>
        /// 获取所有节点数据
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetAllNodeData(SearchModel param)
        {
            await Task.Run(() => { Console.WriteLine("\n获取所有节点数据：GetAllNodeData"); });

            List<ValueModel> result = new List<ValueModel>();

            Console.WriteLine($"Id：{param.Id}");
            if (!string.IsNullOrEmpty(param.Id))
            {
                result = Global.SaveNodeData.Where(w => w.Value.Tag.Contains(param.Id)).Select(s => s.Value).ToList();
            }
            else
            {
                result = Global.SaveNodeData.Select(s => s.Value).ToList();
            }

            return new JsonResult(new ResultModel
            {
                Data = result,
                Count = result.Count
            });
        }

        #endregion

        #region 获取节点配置详情

        /// <summary>
        /// 获取节点配置详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> NodeDataDetail(SearchModel param)
        {
            await Task.Run(() => { Console.WriteLine("\n获取节点配置详情：NodeDataDetail"); });

            #region 参数校验

            Console.WriteLine($"Id：{param.Id}");
            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            var result = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(param.Id)).Value;

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 写入指定节点数据

        /// <summary>
        /// 写入指定节点数据
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> SetNodeData(UpdateModel param)
        {
            await Task.Run(() => { Console.WriteLine("\n写入指定节点数据：SetNodeData"); });

            #region 参数校验

            Console.WriteLine($"SetValueData：{param.SetValueData}");
            if (param.SetValueData == null)
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            bool result = false;
            Parallel.ForEach(param.SetValueData, (item) =>
            {
                switch (item.Type)
                {
                    case "bool":
                        {
                            result = Global.KepServer.Write(item.Id, "1".Equals(item.Value) ? true : false);
                        }
                        break;
                    default:
                        {
                            result = Global.KepServer.Write(item.Id, item.Value);
                        }
                        break;
                }
            });

            return new JsonResult(new ResultModel
            {
                Success = result,
                Msg = $"执行{(result ? "成功" : "失败")}",
                Data = result
            });
        }

        #endregion

        #region 获取全部设备运行状态

        /// <summary>
        /// 获取全部设备运行状态
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> AllDeviceStatusData()
        {
            Console.WriteLine("\n获取全部设备运行状态：AllDeviceStatusData");

            // 获取设备状态点位配置数据
            var DeviceConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.ParamName.Contains("设备状态"));
            if (DeviceConfigData != null && DeviceConfigData.Count > 0)
            {
                Parallel.ForEach(DeviceConfigData, (item) =>
                {
                    try
                    {
                        // 处理返回字段
                        item.Name = item.Name.Replace("开盖机1", "反应釜开盖机");
                        item.Name = item.Name.Replace("开盖机2", "试管开盖机");
                        item.Name = item.Name.Replace("工位", "");
                        item.DefaultValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(item.ParamId)).Value.Value ?? "4";
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        item.DefaultValue = "1";
                    }
                });

                // 20240203需求 - 移除 磁力搅拌镍片蠕动 设备状态数据
                DeviceConfigData.RemoveAll(w => "磁力搅拌捏片蠕动".Equals(w.Name));
            }

            return new JsonResult(new ResultModel
            {
                Data = DeviceConfigData
            });
        }

        #endregion

        #region 获取AGV小车状态详情

        /// <summary>
        /// 获取AGV小车状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetAutoGuideVehicleStatus()
        {
            Console.WriteLine("\n获取AGV小车状态详情：GetAutoGuideVehicleStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Equals("AGV小车工位"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 当前电量
                BatteryPower = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("电池电量水平")).ParamId)).Value.Value ?? "0",
                // 运行时间
                NormalRunningTime1 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("正常运行时间1")).ParamId)).Value.Value ?? "0",
                // 运行距离
                RunningDistance1 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("运行距离1")).ParamId)).Value.Value ?? "0",
                // X位置
                XPosition = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("X位置")).ParamId)).Value.Value ?? "0",
                // Y位置
                YPosition = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("Y位置")).ParamId)).Value.Value ?? "0",
                // 位置方位
                PositionDirection = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("位置方位")).ParamId)).Value.Value ?? "无",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取球磨机状态详情

        /// <summary>
        /// 获取球磨机状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetBallMillingStationStatus()
        {
            Console.WriteLine("\n获取球磨机状态详情：GetBallMillingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("球磨机"));
            dynamic result = new
            {
                // 球磨机1-设备状态
                Status1 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机1") && w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 球磨机1-当前速度
                CurrentVelocity1 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机1") && w.ParamName.Equals("当前速度")).ParamId)).Value.Value ?? "0",
                // 球磨机1-已运行时间
                HasRunTime1 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机1") && w.ParamName.Equals("已运行时间")).ParamId)).Value.Value ?? "0",
                // 球磨机1-已循环次数
                HasCycledNumber1 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机1") && w.ParamName.Equals("已循环次数")).ParamId)).Value.Value ?? "0",
                // 球磨机2-设备状态
                Status2 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机2") && w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 球磨机2-当前速度
                CurrentVelocity2 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机2") && w.ParamName.Equals("当前速度")).ParamId)).Value.Value ?? "0",
                // 球磨机1-已运行时间
                HasRunTime2 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机2") && w.ParamName.Equals("已运行时间")).ParamId)).Value.Value ?? "0",
                // 球磨机2-已循环次数
                HasCycledNumber2 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("球磨机2") && w.ParamName.Equals("已循环次数")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取管式炉状态详情

        /// <summary>
        /// 获取管式炉状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetTubeFurnaceStationStatus()
        {
            Console.WriteLine("\n获取管式炉状态详情：GetTubeFurnaceStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("管式炉"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 加热功率MV及报警状态
                HeatingPowerAndAlarm = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("加热功率MV及报警状态")).ParamId)).Value.Value ?? "无",
                // 真空压力值
                VacuumPressureValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("真空压力值")).ParamId)).Value.Value ?? "0",
                // 当前运行程序段
                CurrentProgramNo = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("当前运行程序段")).ParamId)).Value.Value ?? "0",
                // 温度PV
                TemperaturePracticalValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("温度PV")).ParamId)).Value.Value ?? "0",
                // 温度SV
                TemperatureSettingValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("温度SV")).ParamId)).Value.Value ?? "0",
                // 进气流量PV
                IntakeFlowPracticalValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("进气流量PV")).ParamId)).Value.Value ?? "0",
                // 进气流量SV
                IntakeFlowSettingValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("进气流量SV")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取下装炉状态详情

        /// <summary>
        /// 获取下装炉状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetBottomFurnaceStationStatus()
        {
            Console.WriteLine("\n获取下装炉状态详情：GetBottomFurnaceStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("下装炉"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 加热功率MV及报警状态
                HeatingPowerAndAlarm = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("加热功率MV及报警状态")).ParamId)).Value.Value ?? "无",
                // 温度PV
                TemperaturePracticalValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("温度PV")).ParamId)).Value.Value ?? "0",
                // 温度SV
                TemperatureSettingValue = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("温度SV")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取开盖机状态详情

        /// <summary>
        /// 获取开盖机状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetCapperStationStatus()
        {
            Console.WriteLine("\n获取开盖机状态详情：GetCapperStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("开盖机"));
            dynamic result = new
            {
                // 开盖机1-设备状态
                Status1 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("开盖机1") && w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 开盖机2-设备状态
                Status2 = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.Name.Contains("开盖机2") && w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取坩埚转换位状态详情

        /// <summary>
        /// 获取坩埚转换位状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetCrucibleConversionStationStatus()
        {
            Console.WriteLine("\n获取坩埚转换位状态详情：GetCrucibleConversionStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("坩埚转换位"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取破碎机状态详情

        /// <summary>
        /// 获取破碎机状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetCrusherStationStatus()
        {
            Console.WriteLine("\n获取破碎机状态详情：GetCrusherStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("破碎机"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取电化学测试仪状态详情

        /// <summary>
        /// 获取电化学测试仪状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetElectroChemistryTestingStationStatus()
        {
            Console.WriteLine("\n获取电化学测试仪状态详情：GetElectroChemistryTestingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("电化学测试"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取高通量配粉设备状态详情

        /// <summary>
        /// 获取高通量配粉设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetFlourBlendingStationStatus()
        {
            Console.WriteLine("\n获取高通量配粉设备状态详情：GetFlourBlendingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("高通量配粉"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取ROBOT机器人状态详情

        /// <summary>
        /// 获取ROBOT机器人状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetJakaRobotStatus()
        {
            Console.WriteLine("\n获取ROBOT机器人状态详情：GetJakaRobotStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Equals("ROBOT机器人工位"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 当前程序号
                CurrentProgramNo = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("反馈当前程序号")).ParamId)).Value.Value ?? "0",
                // 当前工位号
                CurrentStationNo = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("反馈当前工位号")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取磁力搅拌捏片蠕动设备状态详情

        /// <summary>
        /// 获取磁力搅拌捏片蠕动设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetMagneticPeristalticOthersStationStatus()
        {
            Console.WriteLine("\n获取磁力搅拌捏片蠕动设备状态详情：GetMagneticPeristalticOthersStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("磁力搅拌捏片蠕动"));
            dynamic result = new
            {
                // 捏片倒料设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("捏片倒料设备状态")).ParamId)).Value.Value ?? "4",
                // 磁力搅拌温度
                MagneticStirringTemperature = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("磁力搅拌温度")).ParamId)).Value.Value ?? "0",
                // 磁力搅拌时间
                MagneticStirringTime = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("磁力搅拌时间")).ParamId)).Value.Value ?? "0",
                // 磁力搅拌转速
                MagneticStirringRotateSpeed = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("磁力搅拌转速")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取烘箱设备状态详情

        /// <summary>
        /// 获取烘箱设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetOvenStationStatus()
        {
            Console.WriteLine("\n获取烘箱设备状态详情：GetOvenStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("烘箱"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 循环次数
                CycleNumber = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("循环次数")).ParamId)).Value.Value ?? "0",
                // 测量温度
                ActualTemperature = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("测量温度")).ParamId)).Value.Value ?? "0",
                // 设定温度
                TargetTemperature = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设定温度")).ParamId)).Value.Value ?? "0",
                // 测量转速
                ActualRotateSpeed = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("测量转速")).ParamId)).Value.Value ?? "0",
                // 设定转速
                TargetRotateSpeed = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设定转速")).ParamId)).Value.Value ?? "0",
                // 运行时间小时
                RunningTimeHour = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("运行时间小时")).ParamId)).Value.Value ?? "00",
                // 运行时间分钟
                RunningTimeMinute = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("运行时间分钟")).ParamId)).Value.Value ?? "00",
                // 设定时间小时
                SettingTimeHour = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设定时间小时")).ParamId)).Value.Value ?? "00",
                // 设定时间分钟
                SettingTimeMinute = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设定时间分钟")).ParamId)).Value.Value ?? "00",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取封装机状态详情

        /// <summary>
        /// 获取封装机状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetPackagingStationStatus()
        {
            Console.WriteLine("\n获取封装机状态详情：GetPackagingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("封装机"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 移动状态
                ShowMoveStatus = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("显示移动状态")).ParamId)).Value.Value ?? "无",
                // 实时压力值
                ActualPressure = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("实时压力值")).ParamId)).Value.Value ?? "0",
                // X坐标
                XAxis = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("X坐标")).ParamId)).Value.Value ?? "0",
                // Y坐标
                YAxis = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("Y坐标")).ParamId)).Value.Value ?? "0",
                // Z坐标
                ZAxis = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("Z坐标")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取压片机状态详情

        /// <summary>
        /// 获取压片机状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetTabletPressStationStatus()
        {
            Console.WriteLine("\n获取压片机状态详情：GetTabletPressStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("压片机"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 运行时间
                RWProgramRunningTime = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("程序运行时间")).ParamId)).Value.Value ?? "0",
                // 保压时间
                RPressureHoldTime = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("保压时间")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取移液配比设备状态详情

        /// <summary>
        /// 获取移液配比设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetPipetteDistributionStationStatus()
        {
            Console.WriteLine("\n获取移液配比设备状态详情：GetPipetteDistributionStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("移液配比"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
                // 当前使用坩埚
                CurrentUsedCrucible = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("当前使用坩埚")).ParamId)).Value.Value ?? "0",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取刷料机设备状态详情

        /// <summary>
        /// 获取刷料机设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetScrapingStationStatus()
        {
            Console.WriteLine("\n获取刷料机设备状态详情：GetScrapingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("刷料机"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取固液测试设备状态详情

        /// <summary>
        /// 获取固液测试设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetSolidLiquidTestingStationStatus()
        {
            Console.WriteLine("\n获取固液测试设备状态详情：GetSolidLiquidTestingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("固液测试"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取固固测试设备状态详情

        /// <summary>
        /// 获取固固测试设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetSolidSolidTestingStationStatus()
        {
            Console.WriteLine("\n获取固固测试设备状态详情：GetSolidSolidTestingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("固固测试"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取XRD测试设备状态详情

        /// <summary>
        /// 获取XRD测试设备状态详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> GetXRDTestingStationStatus()
        {
            Console.WriteLine("\n获取XRD测试设备状态详情：GetXRDTestingStationStatus");

            // 获取设备状态点位配置数据
            var ConfigData = await BisDeviceConfigDao.QueryByWhere(w => w.Del_Flag == 0 && w.Name.Contains("XRD测试"));
            dynamic result = new
            {
                // 设备状态
                Status = Global.SaveNodeData.FirstOrDefault(w => w.Value.Tag.Equals(ConfigData.FirstOrDefault(w => w.ParamName.Equals("设备状态")).ParamId)).Value.Value ?? "4",
            };

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

    }
}